package com.test.thread;

import jdk.internal.vm.Continuation;
import jdk.internal.vm.ContinuationScope;

/**
 * run need add vm option: --enable-preview --add-exports java.base/jdk.internal.vm=ALL-UNNAMED
 */
public class ContinuationsDemo {
    public static void main(String[] args) {
        var continuation = getContinuation();
        continuation.run();
        System.out.println("do something");
        continuation.run();
        continuation.run();
        // continuation.run();
        System.out.println(continuation.isDone());

    }

    private static Continuation getContinuation() {
        var scope = new ContinuationScope("test");
        return new Continuation(scope, () -> {
            System.out.println("A");
            Continuation.yield(scope);
            System.out.println("B");
            Continuation.yield(scope);
            System.out.println("C");
        });
    }
}
